package com.qing.eduservice.controller;


import com.qing.eduservice.entity.pojo.EduChapter;
import com.qing.eduservice.service.EduChapterService;
import com.qing.servicebase.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Yjx
 * @since 2022-09-08
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {

    private final EduChapterService eduChapterService;

    public EduChapterController(EduChapterService eduChapterService) {
        this.eduChapterService = eduChapterService;
    }

    @GetMapping("/list/{courseId}")
    public ResponseResult nestedListByCourseId(@PathVariable String courseId){
        return eduChapterService.nestedList(courseId);
    }

    /**
     * 增加
     * @param chapter
     * @return
     */
    @PostMapping(value = "/add")
    public ResponseResult save(@RequestBody EduChapter chapter){
        return eduChapterService.addChapter(chapter);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/search/{id}")
    public ResponseResult getById(@PathVariable String id){
        return eduChapterService.searchById(id);
    }

    /**
     * 根据id修改
     * @param id
     * @param chapter
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseResult updateById(@PathVariable String id, @RequestBody EduChapter chapter){
        return eduChapterService.updateById(id,chapter);
    }

    /**
     * 删除章节
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult removeById(@PathVariable String id){
        return eduChapterService.removeById(id);
    }


}

